-
Notifications
You must be signed in to change notification settings - Fork 85
Fixes/html entities in version #1693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes/html entities in version #1693
Conversation
aab3983 to
d9d27bf
Compare
… _versionSplicer
d9d27bf to
fc570d1
Compare
| // okay, we have found the thing we are looking for. | ||
| // idx points at the position of the closing " | ||
| // | ||
| // TODO: we cheat here and reference the hp2 internal tokenizer index to find | ||
| // out where the attribute actually is. the parser startIndex and endIndex point | ||
| // at the whitespace preceding the tag until the tag is closed. obviously this is | ||
| // pretty bad but i don't see a more robust solution right now. | ||
| const idx = parser.tokenizer.index; | ||
| const result = replace | ||
| ? `${xml.slice(0, parser.startIndex)}version="${insert}"${xml.slice(parser.endIndex)}` | ||
| : `${xml.slice(0, parser.endIndex-1)}${insert}"${xml.slice(parser.endIndex)}`; | ||
| parser.reset(); | ||
| return replace | ||
| ? pass(`${xml.slice(0, idx - value.length)}${insert}${xml.slice(idx)}`) | ||
| : pass(`${xml.slice(0, idx)}${insert}${xml.slice(idx)}`); | ||
| return pass(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
latest version has fixed the bug around startIndex and endIndex, so we can use that.
lib/data/schema.js
Outdated
| const idx = parser.tokenizer.index; | ||
| const result = replace | ||
| ? `${xml.slice(0, parser.startIndex)}version="${insert}"${xml.slice(parser.endIndex)}` | ||
| : `${xml.slice(0, parser.endIndex-1)}${insert}"${xml.slice(parser.endIndex)}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a subtle change here for the replace case. I think it introduces a bug in untested code paths.
Fix:
| : `${xml.slice(0, parser.endIndex-1)}${insert}"${xml.slice(parser.endIndex)}`; | |
| : `${xml.slice(0, parser.endIndex)}${insert}${xml.slice(parser.endIndex)}`; |
alxndrsn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this aims to fix two separate bugs.
- The fix in
lib/model/frames/form.jsis tested intest/integration/api/forms/forms.js, and looks good, and I could approve immediately if submitted separately. - The fix in
lib/data/schema.jsis tested intest/unit/data/schema.js, and looks like it introduces a surprising bug in an untested code path. I think my suggestion will fix that.
alxndrsn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍

Closes getodk/central#1470
See the analysis of the issue at getodk/central#1470 (comment)
What has been done to verify that this works as intended?
Added couple of tests.
Why is this the best possible solution? Were any other approaches considered?
The bug about
startIndexandendIndexin htmlparser2 mentioned in the previous comment has been fixed in the latest version so I thought it would be good to upgrade it and usestartIndexandendIndexto replace/append version value.We were using quite an old version of htmlparser2 i.e. v3.9 and the current version is v10.0. In one of our meeting we talked about using the latest versions of all dependencies where possible.
The upgrade is done in a separate PR to keep the changes for the actual bug fix minimum: #1692
To review this PR just see the latest commit.
How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
No
Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.
No
Before submitting this PR, please make sure you have:
make testand confirmed all checks still pass OR confirm CircleCI build passes